import React,{Component} from 'react'
import {connect} from 'dva'
import {List, InputItem, WingBlank, WhiteSpace, Button} from 'antd-mobile'
import 'antd-mobile/dist/antd-mobile.css'
import imgsrc from '../../static/images/touxiang.jpeg'
import {Redirect} from 'dva/router'
class Login extends Component{
    constructor(){
        super();
        this.state={
            username:'',
            password:''
        }
    }
    componentDidMount(){
        this.props.dispatch({type:'user/getInfo'});
    }
    handleChange(e,key){
        this.state[key] = e;
    }
    login(){
        let {username,password} = this.state;
        //console.log(username,password);
        this.props.dispatch({type:'user/login',payload:{username:username,password:password}})
    }
    skip2Login(){
        this.props.dispatch({type:'user/skip2Login'});
    }
    render(){
        return(
            <React.Fragment>
                {/* 判断跳转 */}
                
                {this.props.redirectPath? <Redirect to={this.props.redirectPath} />:null}
                
                <img src={imgsrc} style={{width:'60px',height:'60px',margin:'35px auto',border:'1px solid #777',borderRadius:'50%',display:'block'}}></img>
                <WingBlank>
					<List>
                        {/* {this.props.msg?<p className='error-msg'>{this.props.msg}</p>:null} */}
						<InputItem onChange={(e)=>{this.handleChange(e,'username')}}>用户</InputItem>
						<WhiteSpace />
						<InputItem onChange={(e)=>{this.handleChange(e,'password')}} type='password'>密码</InputItem>
					</List>
					<WhiteSpace />
					<Button  type='primary' onClick={()=>{this.login()}}>登录</Button>
					<WhiteSpace />
					<Button  type='primary' onClick={()=>{this.skip2Login()}}>注册</Button>
				</WingBlank>
            </React.Fragment>
        )
    }
}
const mapStateProps = (state)=>{
    return{
        username:state.user.username,
        password:state.user.password,
        redirectPath:state.user.redirectPath,
    }
}
export default connect(mapStateProps)(Login);